package com.cx.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author cx
 * @since 2024-06-07
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_article_comment")
@ApiModel(value = "ArticleComment对象")
public class ArticleComment implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "评论表主键")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "关联的文章id")
    private Integer articleId;

    @ApiModelProperty(value = "外键（用户表）用户id")
    private Integer userId;

    @ApiModelProperty(value = "父评论PID")
    private Integer pid;

    @ApiModelProperty(value = "评论的内容")
    private String plContent;


    @ApiModelProperty(value = "评论状态")
    private String status;

    @ApiModelProperty(value = "评论用户登录的ip地址")
    private String ip;

    @ApiModelProperty(value = "评论时间")
    private Date created;

    @ApiModelProperty(value = "子评论列表")
    @TableField(exist = false)
    private List<ArticleComment> children;

    // 添加子评论到列表中的方法
    public void addChild(ArticleComment child) {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        this.children.add(child);
    }
}
